//
//  MineViewController.m
//  shopping
//
//  Created by 马田成 on 2017/8/30.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "MineViewController.h"
#import "MineFirstTableViewCell.h"
//#import "MineOrderSecondTableViewCell.h"//原来的订单
#import "FuckFuckFuckTableViewCell.h"//新订单
#import "MineImgNewTableViewCell.h"
#import "MineIntegralRootViewController.h"//我的积分
#import "MineSettingViewController.h"
#import "ScucureViewController.h"
#import "InsuranceViewController.h"

#import "MessageLineViewController.h"
#import "MessageDetailViewController.h"
//#import "CrowdFundingViewController.h"
#import "ManagerMoneyViewController.h"
//#import "BindingAcountViewController.h"//绑定账号
#import "MineAddressRootViewController.h"
#import "PersonalInfoViewController.h"
#import "HoneyAndStoreViewController.h"
#import "myEvaluteViewController.h"
#import "MineTuiJianListViewController.h"//我的推荐
#import "caiwurizhiViewController.h"//财务记录
//#import "JieChuBangDingViewController.h"//解除绑定
#import "zhuanBiViewController.h"//转币
#import "CommentManagerController.h"

#import "BindingAcountViewController.h"
#import "JieChuBangDingViewController.h"
#import "aaaaaaaaaaaaaViewController.h"

#import "kefuViewController.h"//客服
#import "LoginViewController.h"
@interface MineViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableDictionary *dataDic;



@end

@implementation MineViewController
- (void)viewWillAppear:(BOOL)animated{
    
    
    [super viewWillAppear:animated];
    [self creationData];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creationView];
    [self regeditCell];
    
    // Do any additional setup after loading the view.
}
- (void)creationView{

    

    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 20, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 69 - 45);
    
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //   self.tableView.estimatedRowHeight = 400;
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线
    
    
    [self.view addSubview:self.tableView];
    self.view.backgroundColor = [UIColor colorWithRed:245 / 255.0f green:245 / 255.0f blue:245 / 255.0f alpha:1];
    
    UIButton *buttonOut = [[UIButton alloc] init];
    [self.view addSubview:buttonOut];
    [buttonOut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(self.view);
        make.height.offset(45);
        
    }];
    [buttonOut setTitle:@"退出登录" forState:UIControlStateNormal];
    buttonOut.backgroundColor = [UIColor whiteColor];
    [buttonOut setTitleColor:getColor(@"222222") forState:UIControlStateNormal];
    [buttonOut addTarget:self action:@selector(outLick) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *view = [[UIView alloc] init];
    [self.view addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.bottom.equalTo(buttonOut.mas_top);
        make.height.offset(1);
        
    }];
    view.backgroundColor = getColor(@"eeeeee");

    
    
    
    
    
}
- (void)creationData{
    
    _dataDic = [[NSMutableDictionary alloc] init];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:adminLxlpersonupdate networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"status"]intValue]==1) {
            
            self.dataDic = [returnData objectForKey:@"data"];
            
            
            [self.tableView reloadData];
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    

}

- (void)regeditCell{
    
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MineFirstTableViewCell" bundle:nil] forCellReuseIdentifier:@"MineFirstTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"MineOrderSecondTableViewCell" bundle:nil] forCellReuseIdentifier:@"MineOrderSecondTableViewCell"];
     [self.tableView registerNib:[UINib nibWithNibName:@"FuckFuckFuckTableViewCell" bundle:nil] forCellReuseIdentifier:@"FuckFuckFuckTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MineImgNewTableViewCell" bundle:nil] forCellReuseIdentifier:@"MineImgNewTableViewCell"];
    
}
#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 12;
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 130;
    }else if (indexPath.row == 1){
    
        return 140;
    }else {
    
        return 50;
        
    }
    
   
    
}

#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        MineFirstTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MineFirstTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        [cell.settttButton addTarget:self action:@selector(settinfClick) forControlEvents:UIControlEventTouchUpInside];
        
//        NSString *urlWare=[self.dataDic objectForKey:@"userPhoto"];
//        NSString *urlN=manage(AP_Img, urlWare);
        
//        [cell.headImg sd_setImageWithURL:[NSURL URLWithString:urlN] placeholderImage:[UIImage imageNamed:@"geren_touxiang"]];
        
        
        cell.nameLabel.text = [self.dataDic objectForKey:@"loginName"];
        cell.phoneLabel.text = [self.dataDic objectForKey:@"userPhone"];
        
        
        NSString *urlN=manage(AP_HOST, [self.dataDic objectForKey:@"userPhoto"]);
        [cell.headImg sd_setImageWithURL:[NSURL URLWithString:urlN] placeholderImage:[UIImage imageNamed:@"geren_touxiang"]];
        
        
        return cell;
        
    }else if (indexPath.row == 1){
//        MineOrderSecondTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MineOrderSecondTableViewCell" forIndexPath:indexPath];
//        
//        cell.selectionStyle=UITableViewCellSelectionStyleNone;
//        cell.secondViewController=self;
//        
//        return cell;
        
        FuckFuckFuckTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"FuckFuckFuckTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.secondViewController=self;
        
        return cell;
        
        
        
        
    }else {
        MineImgNewTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MineImgNewTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
//        NSArray *arr = @[@"我的积分", @"我的消息",@"安全中心",@"我的增值", @"我的公益", @"收货地址",@"收藏宝贝", @"我的分享", @"我的评价", @"财务记录",@"转资产包"];
        
        
        NSArray *arr = @[@"我的分红", @"我的消息",@"安全中心", @"收货地址",@"收藏宝贝", @"我的分享", @"我的评价", @"财务记录",@"离场",@"客服"];
        cell.leftLabel.text = arr[indexPath.row - 2];
//        NSArray *arrOfPic = @[@"jifen",@"xiaoxi",@"anquan", @"licai",@"gongyi",@"shouhuo",@"shoucang",@"tuijian",@"pingjia",@"caiwu",@"zhuanzichan"];
        NSArray *arrOfPic = @[@"jifen",@"xiaoxi",@"anquan",@"shouhuo",@"shoucang",@"tuijian",@"pingjia",@"caiwu",@"zhuanzichan",@"kehuaaaaaa"];
        
        
        cell.img.image = [UIImage imageNamed:arrOfPic[indexPath.row - 2]];
        
        return cell;
        
        
    }

    
    
    
}
#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        PersonalInfoViewController *vc = [[PersonalInfoViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 2) {
        MineIntegralRootViewController *vc = [[MineIntegralRootViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 3){
    
        MessageLineViewController *vc = [[MessageLineViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 4) {
    
        ScucureViewController *vc = [[ScucureViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
    
        [self.navigationController pushViewController:vc animated:YES];
        
        
    }
//    else if (indexPath.row == 5){
//        
//        
//        //绑定账号
//        
//        NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
//        NSString *token = [PublicFunction getConfigWithKey:@"token"];
//        // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
//        
//        [productParams setValue:token forKey:@"token"];
//        [[MNetworkHandler sharedInstance]conURL:adminUserJudgeBindAccount networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
//            
//            if ([[returnData objectForKey:@"code"]intValue]==1) {
//                
//                JieChuBangDingViewController *vc = [[JieChuBangDingViewController alloc] init];
//                
//                vc.hidesBottomBarWhenPushed = YES;
//                NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
//                dic = [returnData objectForKey:@"data"];
//                vc.nameStr = [dic objectForKey:@"name"];
//                [self.navigationController pushViewController:vc animated:YES];
//                
//            }else {
//                
//                BindingAcountViewController * modifier = [[BindingAcountViewController alloc] init];
//                
//                modifier.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:modifier animated:YES];
//                
//            }
//            
//        } failureBlock:^(NSError *error) {
//            
//            NSLog(@"%@",error);
//            
//            [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
//            
//        }];
//
//        
//    
//    }
//    else if (indexPath.row == 5) {
//        
//        ManagerMoneyViewController *vc = [[ManagerMoneyViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        
//        [self.navigationController pushViewController:vc animated:YES];
//        
//    }else if (indexPath.row == 6) {
//        
//        InsuranceViewController *vc = [[InsuranceViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        
//        [self.navigationController pushViewController:vc animated:YES];
//    }
//    else if (indexPath.row == 8) {
//        
//        CrowdFundingViewController *vc = [[CrowdFundingViewController alloc] init];
//        vc.hidesBottomBarWhenPushed = YES;
//        
//        [self.navigationController pushViewController:vc animated:YES];
//        
//        
//    }
    else if (indexPath.row == 5){
    
        MineAddressRootViewController *vc = [[MineAddressRootViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        vc.style = @"1";
        [self.navigationController pushViewController:vc animated:YES];
        
        
    }else if (indexPath.row == 6){
        
        HoneyAndStoreViewController *vc = [[HoneyAndStoreViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 8){
        
        CommentManagerController * vc = [[CommentManagerController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    
    }else if (indexPath.row == 7){
    
        MineTuiJianListViewController *vc = [[MineTuiJianListViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    
    }else if (indexPath.row == 9){
    
        caiwurizhiViewController *vc = [[caiwurizhiViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    
    }else if (indexPath.row == 10){
    
        NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
        NSString *token = [PublicFunction getConfigWithKey:@"token"];
        // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
        
        [productParams setValue:token forKey:@"token"];
        [[MNetworkHandler sharedInstance]conURL:adminUserJudgeBindAccount networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
            
            if ([[returnData objectForKey:@"code"]intValue]==1) {
                
                zhuanBiViewController *vc = [[zhuanBiViewController alloc] init];
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            }else {
                
                BindingAcountViewController * modifier = [[BindingAcountViewController alloc] init];
                
                modifier.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:modifier animated:YES];
                
            }
            
        } failureBlock:^(NSError *error) {
            
            NSLog(@"%@",error);
            
//            [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
            
        }];

        
        
        
        
        
    }
    else if (indexPath.row == 11){
        
        kefuViewController *vc = [[kefuViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
        
    }
    
    
    
    
}
- (void)settinfClick{
    MineSettingViewController *vc = [[MineSettingViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    

    
}

- (void)outLick{
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    
    [productParams setValue:token forKey:@"token"];
    
    
    [[MNetworkHandler sharedInstance]conURL:adminLoginloginOut networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            
            [PublicFunction removeConfigWithKey:@"token"];
            
            
            LoginViewController *vc = [[LoginViewController alloc] init];
            vc.hidesBottomBarWhenPushed = YES;
            
            [self.navigationController pushViewController:vc animated:YES];
            
        }
        
        else {
            
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
            
        }
        
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        //        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
        
    }];
    
    
    
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
